package _021_10_4

import "strconv"

//7 9 13 15 17
//19+13
//12+20=22

func addStrings(num1 string, num2 string) string {
	bStrNum := ""
	sStrNum := ""
	bStrNum = num2
	sStrNum = num1
	if len(num1) > len(num2) {
		bStrNum = num1
		sStrNum = num2
	}
	overFlow := false
	result := ""

	for i := 0; i < len(sStrNum); i++ {
		temp := sStrNum[len(sStrNum)-i-1] - '0' + bStrNum[len(bStrNum)-i-1] - '0'
		if overFlow {
			temp++
		}
		overFlow = false
		if temp >= 10 {
			overFlow = true
		}
		result += string(uint8(temp%10) + '0')
	}
	for i := len(sStrNum); i < len(bStrNum); i++ {
		temp := bStrNum[len(bStrNum)-1-i] - '0'
		if overFlow {
			temp++
		}
		overFlow = false
		if temp >= 10 {
			overFlow = true
			temp %= 10
		}
		result += string(temp + '0')

	}
	if overFlow {
		result += string('1')
	}
	result2 := ""
	for i := 0; i < len(result); i++ {
		result2 += string(result[len(result)-1-i])
	}
	return result2
}
func addStrings2(num1 string, num2 string) string {
	bStrNum := ""
	sStrNum := ""
	bStrNum = num2
	sStrNum = num1
	if len(num1) > len(num2) {
		bStrNum = num1
		sStrNum = num2
	}
	sum := 0
	multiple := 1
	for i := 0; i < len(sStrNum); i++ {
		_num1 := (int(sStrNum[len(sStrNum)-1-i] - '0')) * multiple
		_num2 := (int(bStrNum[len(bStrNum)-1-i] - '0')) * multiple
		sum += _num1 + _num2
		multiple *= 10
	}
	for i := len(sStrNum); i < len(bStrNum); i++ {
		sum += multiple * int(bStrNum[len(bStrNum)-i-1]-'0')
		multiple *= 10
	}

	return strconv.Itoa(sum)
}
